
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title> 我的紀錄 </title>
  <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.21/jquery-ui.min.js"></script>

  <style>
    .ui-autocomplete-loading { background: white url('http://jqueryui.com/demos/autocomplete/images/ui-anim_basic_16x16.gif') right center no-repeat; }
  </style>

  <script>
    //datepicker for calendar
    $(function() {
      $( "#date_report" ).datepicker();
    });
    
  $(function() {
    $( "#search_disease" ).autocomplete({
        source: "/search_disease/?"
    }); //autocomplete
  });

  $(function() {
    $( "#search_medicine" ).autocomplete({
        source: "/search_medicine/?"
    }); //autocomplete
  });

  $(function() {
    function split( val ) {
      return val.split( /,\s*/ );
    }
    function extractLast( term ) {
      return split( term ).pop();
    }

    $( "#search_side_effect" )
      // don't navigate away from the field on tab when selecting an item
      .bind( "keydown", function( event ) {
        if ( event.keyCode === $.ui.keyCode.TAB &&
            $( this ).data( "autocomplete" ).menu.active ) {
          event.preventDefault();
        }
      })
      .autocomplete({
        source: function( request, response ) {
          $.getJSON( "/search_side_effect/?", {
            term: extractLast( request.term )
          }, response );
        },
        search: function() {
          // custom minLength
          var term = extractLast( this.value );
          if ( term.length < 1 ) {
            return false;
          }
        },
        focus: function() {
          // prevent value inserted on focus
          return false;
        },
        select: function( event, ui ) {
          var terms = split( this.value );
          // remove the current input
          terms.pop();
          // add the selected item
          terms.push( ui.item.value );
          // add placeholder to get the comma-and-space at the end
          terms.push( "" );
          this.value = terms.join( ", " );
          return false;
        }
      }); //end autocomplete
  });
  </script>
</head>


<body>
<form action="/add_report" name="add" id="report" method="POST">
  疾病名稱: <input id="search_disease" type="text" name="term" /> <br>
  Date: <input id="date_report" type="text"> <br>
  藥名: <input id="search_medicine"    type="text" name="term" /> <br>
  副作用: <input id="search_side_effect" type="text" name="term" />
  <input id="search_input" type="submit" value="送出" />
</form>
</body>
</html>


